<?php

if (!defined('IN_IA')) {
	exit('Access Denied');
}

class Index_EweiShopV2Page extends PluginWebPage
{
	public function main()
	{
		global $_W;
		global $_GPC;

		$level = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_identity') . ' WHERE uniacid = :uniacid AND levelnum = 0', array(':uniacid' => $_W['uniacid']));
		if(empty($level)){
			pdo_insert('ewei_shop_identity', array('uniacid' => $_W['uniacid'], 'levelnum' => 0, 'name' => '默认等级', 'status' => 1, 'add_time' => time(), 'useful_time' => 36500));
		}


		$list = pdo_fetchall("SELECT * FROM " . tablename('ewei_shop_identity') . " WHERE uniacid = :uniacid ORDER BY id ASC LIMIT 20", array(':uniacid' => $_W['uniacid']));

		$version = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_version') . ' WHERE uid=:uid AND `type`=0', array(':uid' => $_W['uid']));
		// 1是V3版   0是V2版
		if($version['version'] == 1){
			// header("Location: ".webUrl('mendian/user'));
			include $this->template();
		} else {
			header("Location: ".webUrl('switchversion',array('route' => 'identity')));
		}
		
		
	}

	public function ajaxuser()
	{
		global $_GPC;
		global $_W;
		$totals = $this->model->getUserTotals();
		$order0 = $this->model->getMerchOrderTotals(0);
		$order3 = $this->model->getMerchOrderTotals(3);
		$totals['totalmoney'] = $order0['totalmoney'];
		$totals['totalcount'] = $order0['totalcount'];
		$totals['tmoney'] = $order3['totalmoney'];
		$totals['tcount'] = $order3['totalcount'];
		show_json(1, $totals);
	}
}

?>
